//
//  MYGHealthManagementSportCell.swift
//  MYGrow
//
//  Created by 林矗 on 2024/3/9.
//

import UIKit

class MYGHealthManagementSportCell: MYGHealthManagementBaseCell {
    // MARK: - Property
    
    override var model: MYGHealthManagementRowModel? {
        didSet {
            guard let model = (model as? MYGHealthManagementSportModel) else { return }
            todayView.content  = model.today
            compareView.content = model.lastDayCompare
//            timeView.content = model.time
        }
    }
    

    // MARK: - init
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        contentView.backgroundColor = .white
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    // MARK: - UI
    private func configUI() {
        contentView.addSubviews([
            bgImageView
        ])
        
        bgImageView.addSubviews([
            iconImageView,
            titleLabel,
            todayView,
            compareView,
            timeView
        ])
        
        bgImageView.snp.makeConstraints { make in
            make.top.equalTo(15)
            make.left.right.equalToSuperview().inset(22.5)
            make.height.equalTo(104)
            make.bottom.equalToSuperview()
        }
        
        iconImageView.snp.makeConstraints { make in
            make.top.equalTo(16.5)
            make.left.equalTo(13.5)
            make.size.equalTo(CGSize(width: 22, height: 22))
        }
        
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(iconImageView.snp.right).offset(4.5)
            make.centerY.equalTo(iconImageView)
            make.height.equalTo(21)
        }
        
        todayView.snp.makeConstraints { make in
            make.left.equalTo(13.5)
            make.top.equalTo(iconImageView.snp.bottom).offset(10)
            make.bottom.equalTo(-8)
        }
        
        compareView.snp.makeConstraints { make in
            make.left.equalTo(todayView.snp.right)
            make.top.equalTo(iconImageView.snp.bottom).offset(10)
            make.bottom.equalTo(-8)
            make.width.equalTo(todayView)
        }
        
        timeView.snp.makeConstraints { make in
            make.left.equalTo(compareView.snp.right)
            make.top.equalTo(iconImageView.snp.bottom).offset(10)
            make.bottom.equalTo(-8)
            make.width.equalTo(todayView)
            make.right.equalTo(-50)
        }
        
    }
    
    // MARK: - lazy load
    private lazy var bgImageView: UIImageView = {
        let imageV = UIImageView(image: UIImage(named: "sport_bg"))
        imageV.contentMode = .scaleAspectFill
        imageV.clipsToBounds = true
        imageV.isUserInteractionEnabled = true
        return imageV
    }()
    
    private lazy var iconImageView: UIImageView = {
        let imageV = UIImageView(image: UIImage(named: "sport_icon"))
        imageV.contentMode = .scaleAspectFill
        imageV.clipsToBounds = true
        return imageV
    }()
    
    private lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.font = .regular(15)
        label.text = "运动"
        label.textColor = .rgba(70, 156, 254)
        return label
    }()
    
    private lazy var todayView: MYGHealthManagementTitleValueView = {
        let view = MYGHealthManagementTitleValueView(frame: .zero)
        view.title = "今日运动"
        view.alignment = .left
        return view
    }()
    
    private lazy var compareView: MYGHealthManagementTitleValueView = {
        let view = MYGHealthManagementTitleValueView(frame: .zero)
        view.title = "对比昨天"
        view.alignment = .left
        return view
    }()
    
    private lazy var timeView: MYGHealthManagementTitleValueView = {
        let view = MYGHealthManagementTitleValueView(frame: .zero)
        view.isHidden = true
        view.title = "运动时间"
        view.alignment = .left
        return view
    }()
}
